package jalus.service;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class WidgetService {
	private static WidgetService instance = new WidgetService();
	private WidgetService(){
	}
	public static WidgetService getInstance(){
		return instance;
	}
	
	public void getAllWidget(Map<String, Object> root){
		getTagList(root);
		getRecentPostList(root);
		getRecentCommentList(root);
		getBlogLinkList(root);
		getArchiveList(root);
	}
	
	public void getSpecifiedWidget(Map<String, Object> root, String... widgetList){
		for(String widget : widgetList){
			if(widget.equalsIgnoreCase("taglist")){
				getTagList(root);
			}else if(widget.equalsIgnoreCase("recentpost")){
				getRecentPostList(root);
			}else if(widget.equalsIgnoreCase("recentcomment")){
				getRecentCommentList(root);
			}else if(widget.equalsIgnoreCase("bloglink")){
				getBlogLinkList(root);
			}else if(widget.equalsIgnoreCase("archive")){
				getArchiveList(root);
			}
		}
	}
	
	public void getTagList(Map<String, Object> root){
		List<jalus.pojo.Tag> tagList = TagService.getInstance().getAllTag(); 
		if(tagList == null){
			tagList = new ArrayList<jalus.pojo.Tag>();
		}
		root.put("taglist", tagList);
	}
	public void getRecentPostList(Map<String, Object> root){
		int recentPostNum = ConfigureService.getInstance().getRecentPostCount();
		List<jalus.pojo.Post> postList = PostService.getInstance().getRecentPost(recentPostNum); 
		root.put("recentpostlist", postList);
	}
	public void getRecentCommentList(Map<String, Object> root){
		int recentCommentNum = ConfigureService.getInstance().getRecentCommentCount();
		List<jalus.pojo.Comment> commentList = CommentService.getInstance().getRecentComment(recentCommentNum); 
		root.put("recentcommentlist", commentList);
	}
	public void getBlogLinkList(Map<String, Object> root){
		List<jalus.pojo.BlogLink> blogLinkList = BlogLinkService.getInstance().getAll();
		root.put("bloglinklist", blogLinkList);
	}
	public void getArchiveList(Map<String, Object> root){
		List<jalus.pojo.Tag> archiveList = ArchiveService.getInstance().getAllArchiveList();
		root.put("archivelist", archiveList);
	}
}
